package com.example.gitstudy.mail.controller;

import com.example.gitstudy.mail.util.EmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * @author hwj
 * @date 2023/1/30 11:12
 * @描述；
 */
@RestController
@RequestMapping("mail")
public class MailController {

    @Autowired(required = false)
    private EmailUtil emailUtil;

   @GetMapping("sendMail")
   public void sendStringEmail() {


        // 测试文本邮件发送（无附件）
        String to = "1215335054@qq.com"; // 这是个假邮箱，写成你自己的邮箱地址就可以
        String title = "文本邮件发送测试";
        String content = "文本邮件发送测试";
        emailUtil.sendMessage(to, title, content);
    }


    @GetMapping("sendMail1")
    public void sendFileEmail() {
        // 测试单个附件邮件发送
        String to = "1215335054@qq.com"; // 这是个假邮箱，写成你自己的邮箱地址就可以
        String title = "单个附件邮件发送测试";
        String content = "单个附件邮件发送测试";
        File file = new File("F:\\test\\导出模板.docx");
        emailUtil.sendMessageCarryFile(to, title, content, file);
    }

    @GetMapping("sendMail2")
    public void sendFilesEmail() {
        // 测试多个附件邮件发送
        String to = "1215335054@qq.com"; // 这是个假邮箱，写成你自己的邮箱地址就可以
        String title = "多个附件邮件发送测试";
        String content = "多个附件邮件发送测试";
        File [] files = new File[2];
        files[0] = new File("F:\\test\\导出模板.docx");
        files[1] = new File("F:\\test\\导出模板数据.docx");
        emailUtil.sendMessageCarryFiles(to, title, content, files);
    }

}
